package edu.iwyf.pms.dao;

import edu.iwyf.pms.dao.sql.PermissionSQL;
import edu.iwyf.pms.entity.SysPresmission;
import edu.iwyf.pms.entity.SysRole;
import org.apache.ibatis.annotations.*;

import java.util.List;


/**
 * @Author 王永飞
 * 2021/12/23 13:56
 */
public interface SysPermissionDao {

//    @Select({
//            "<script>",
//            "select pm.id,name,url,icon,parentid,orderid,status,description",
//            "from sys_permission pm join sys_premission_role rpm on pm.id = rpm.premissionid",
//            "where status=1 and roleid in",
//            "<foreach collection=\"roleList\" item=\"item\" index=\"index\" open=\"(\" separator=\",\" clos=\")\">",
//            "#{item.id}",
//            "</foreach>",
//            "order by orderid",
//            "</script>"
//    })
    @SelectProvider(type = PermissionSQL.class,method = "selecttMenu")
    @Results({
            @Result(column = "id",property = "id"),
            @Result(column = "name",property = "name"),
            @Result(column = "url",property = "url"),
            @Result(column = "icon",property = "icon"),
            @Result(column = "parentid",property = "parentid"),
            @Result(column = "orderid",property = "orderid"),
            @Result(column = "status",property = "status"),
            @Result(column = "description",property = "description"),
            @Result(column = "id",property = "subPremissionList",many = @Many(select = "edu.iwyf.pms.dao.SysPermissionDao.selectSubListByParentId")),
    })
    List<SysPresmission> selectByRoleId(@Param(value = "roleList")Integer[] roleList);

    @Select("select * from sys_permission where status=1 and parentid=#{id} order by orderid")
    List<SysPresmission> selectSubListByParentId(@Param("id")int id);

}
